package app.server.project.main.service.db.entity.cfg;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import lombok.Data;
import org.hibernate.annotations.Comment;

@Data
@Entity(name = "lang_cfg")
@TableName("lang_cfg")
@Comment(value = "任务语言表")
public class LangCfgEntity {

    @Id
    @Column(name = "id")
    @Comment("类型id")
    @TableId("id")
    private String id;


    @Column(name = "lid")
    @Comment("类型id")
    @TableField("lid")
    @JsonSerialize(using = ToStringSerializer.class)
    private long lid;

    @Column(name = "type")
    @Comment("类型")
    @TableField("type")
    private String type;

    @Column(name = "val", length = Integer.MAX_VALUE)
    @Comment("值")
    @TableField("val")
    private String val;

    public static LangCfgEntity of(long lid, String type, String val) {
        LangCfgEntity langCfgEntity = new LangCfgEntity();
        langCfgEntity.setId(String.format("%s_%s", lid, type));
        langCfgEntity.setVal(val);
        return langCfgEntity;
    }
}
